const chromeMng = require('../mng/chromeMng')
const config = require('../util/config')
const logger = require('log4js').getLogger()

module.exports = (req, res) => {
  require('../util/service').handlePost(req, res, async (reqObj, resolve) => {
    if (config.domain == '') {
      chromeMng.getJdBill().then(result => {
        resolve({
          result: 1,
          jdBill: result
        })
      }, result => {
        if (result)
          logger.error('[' + __filename + ':' + __line + ']', result)
        else
          result = '系统错误'
        resolve({
          result: -1,
          msg: result
        })
      })
    } else if (config.domain == 'zoro.site') {
      // require('../util/getHtml')({
      //   url: require('../mng/chromeServerMng').get() + 'getJdBill.do',
      //   data: JSON.stringify({})
      // }).then(result => {
      //   var obj = JSON.parse(result)
      //   if (obj.result == 1) {
      //     require('../task/getJdBillTask1').getJdBillResolve(obj.jdBill)
      //   }
      //   resolve(obj)
      // })
      require('../task/getJdBillTask').start()
      resolve({
        result: 1
      })
    }
  })
}